////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   CustomTextTag.java
// AUTHOR           :   Ric Yik
// DATE CREATE      :   2006/4/6
// DESCRIPTION      :   
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/06/06   Ric Yik         1.0                 BugZilla #6140                 
// 2006/06/07   Ric Yik         1.0                 BugZilla #6140
//
////////////////////////////////////////////////////////////////////////////////

//JSP Cache: G:\jboss-4.0.2RC1\server\default\work

package com.erp.app.login.web;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.admin.companySetup.pk.CompanyPk;
import com.erp.app.admin.companySetup.vo.CompanyVo;
import com.erp.app.admin.errorMsg.pk.ErrorMsgLabelPk;
import com.erp.app.admin.errorMsg.vo.ErrorMsgLabelVo;
import com.erp.app.admin.projParam.criteria.ProjectParamSrchCriteria;
import com.erp.app.admin.projParam.vo.ProjectParamVo;
import com.erp.app.admin.projParam.vo.ProjectParamsList;
import com.erp.app.admin.sysLang.criteria.SysLangSrchCriteria;
import com.erp.app.admin.sysLang.vo.SysLangVo;
import com.erp.app.admin.sysParam.beans.SysParamDelegate;
import com.erp.app.admin.sysParam.beans.SysParamList;
import com.erp.app.admin.sysParam.beans.SysParamVO;
import com.erp.app.admin.userSetup.pk.UserPk;
import com.erp.app.admin.userSetup.vo.UserVo;
import com.erp.app.common.ProjectConstants;
import com.erp.app.common.insert.beans.InsertDelegate;
import com.erp.app.common.query.DynamicQuery;
import com.erp.app.common.query.DynamicQueryColumn;
import com.erp.app.common.select.beans.SelectDelegate;
import com.erp.app.util.web.ActionErrorUtil;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.action.SimpleUserStyleAction;
import com.erp.framework.model.delegate.SimplePageEditStyleDelegate;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

public class LoginAction extends SimpleUserStyleAction {

    public static final String actionAuthenticate = "authenticate";
    public static final String actionChangeLang = "changeLang";

    protected String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response) {
        return "";
    }

    public ActionForward otherExecute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response) throws ServletException {

        HttpSession session = request.getSession(false);

        boolean handled = false;

        handled = isHandled(request);

        //perform cleanup on session and removes all previously stored session values.
        if (session != null)
            session.invalidate();
        session = request.getSession(true);

        if (handled) {
            setHandled(request);
        } else {
            resetHandled(request);
        }

        Logger.debug(this, "otherExecute(), session id=" + session.getId());

        ActionErrors errors = new ActionErrors();

        LoginForm form = (LoginForm) formIn;
        ActionForward actionForward = new ActionForward(mapping.getInput());

        String action = form.getPageEvent();
        action = (action == null) ? "" : action.trim();

        form.setCodeUpperCase();

        Servlet servlet = this.getServlet();
        ServletContext scontext = servlet.getServletConfig().getServletContext();
        int defaultLogLevel = CommonUtil.strToBigDecimal(scontext.getInitParameter("defaultLogLevel")).intValue();
        Logger.setLogLevel(defaultLogLevel);

        System.setProperty("LOG_LEVEL", String.valueOf(Logger.getLogLevel()));
        Logger.info("Logger.logLevel = " + Logger.getLogLevelDesc(Logger.getLogLevel()));
        Logger.info("Logger.logTimestamp = " + Logger.isLogTimestamp());
        Logger.info("Logger.logToFile = " + Logger.isLogToFile());
        Logger.info("System.getProperty(\"LOG_LEVEL\") = " + System.getProperty("LOG_LEVEL"));

        Logger.debug(this, "otherExecute(), action = " + action + ", mode = " + form.getPageMode());
        
        // for initial status
        if (!isHandled(request) && action.length() == 0) {
            form.reset(mapping, request);
            form.setPageMode("begin");
            setHandled(request);
        }              

        if (!isHandled(request) && action.equalsIgnoreCase(actionAuthenticate)) {
            // performs form validation
            errors = form.otherValidate(mapping, request);

            if (errors.size() == 0) {
                String comp_code = form.getCompanyCode();
                String user_id = form.getUserID();
                String password = form.getPassword();

                if (!CommonUtil.isEmpty(user_id)) {
                    user_id = user_id.toUpperCase().trim();
                }

//                if (!CommonUtil.isEmpty(password)) {
//                    password = password.toUpperCase();
//                }

                Logger.debug(this, "otherExecute(), company_code = " + comp_code + ", user = " + user_id);
                try {
//                    UserMasterDelegate dg = new UserMasterDelegate();
                	SimplePageEditStyleDelegate dg = new SimplePageEditStyleDelegate();
//                    UserMasterVO model = (UserMasterVO) UserMasterVO.class.newInstance();
                    UserVo userVO = (UserVo) dg.findByPrimaryKey(new UserVo(), new UserPk(form.getUserID().trim().toUpperCase(), form
                            .getCompanyCode()));

                    Logger.field(this, "form.getUserID()=" + form.getUserID() + ", form.getCompanyCode()="
                            + form.getCompanyCode());
                    if (userVO != null) {
                        Logger.all(this, "LoginAction, userVO is NOT null");
                        String correct_password = CommonUtil.nullToString(userVO.getPassword());

                        String activation = userVO.getActivation();

                        userVO.setActivation((activation == null) ? ProjectConstants.GENERIC_INACTIVE : activation);
                        Logger.field(this, "id=" + userVO.getUserCode());
                        Logger.field(this, "pw=" + userVO.getPassword());
                        Logger.field(this, "form.getUserID()=" + form.getUserID());
                        Logger.field(this, "form.getPassword()=" + form.getPassword());

                        System.setProperty("COMPANY_CODE", userVO.getCompanyCode());
                        Logger.debug("System.getProperty(\"COMPANY_CODE\") = " + System.getProperty("COMPANY_CODE"));

                        if (userVO.getActivation().equals(ProjectConstants.GENERIC_ACTIVE)) {
                            boolean caseSensitive = !ProjectConstants.GENERIC_NO.equals(new SelectDelegate().selectOneValue("SELECT PRJ_PARAM_VAL FROM T_PROJECT_PARAM WHERE COMPANY_CODE = '" + userVO.getCompanyCode() + "' AND PRJ_PARAM_ID = '" + ProjectConstants.PP_PASSWORD_CASE_SENSITIVE + "'"));
                            boolean passwordMatched = (caseSensitive) ? password.equals(correct_password.trim()) : password.equalsIgnoreCase(correct_password.trim());
                            if (correct_password != null && passwordMatched) {
                                Logger.all(this, "LoginAction, Login OK");
                                System.gc();
                                String roleGroupId = (userVO.getRoleGroupId() == null) ? "" : userVO.getRoleGroupId().toString();
                                String groupLevel = (userVO.getGroupLevel() == null) ? "" : userVO.getGroupLevel().toString();
                                String userGroupCode = (userVO.getUserGroupCode() == null) ? "" : userVO.getUserGroupCode()
                                        .toString();
                                String deptCode = (userVO.getDept() == null) ? "" : userVO.getDept().toString();
                                String userName = (userVO.getUserName() == null) ? "" : userVO.getUserName().toString();

                                SelectDelegate sdg = new SelectDelegate();
                                String table = "T_CODE_DTL";
                                String column = "REF_DESC";
                                String where = "REF_MASTER_CODE='" + ProjectConstants.CD_DEPT + "'" + " AND REF_CODE='" + deptCode + "'";
                                String deptDesc = (String) sdg.findField(table, column, where);

                                User user = new User(userVO.getCompanyCode(), userVO.getUserCode(), userName, roleGroupId,
                                        groupLevel, userGroupCode, deptCode, deptDesc, userVO.getEmail());
//                                CompanyMasterDelegate compDg = new CompanyMasterDelegate();
//                                CompanyVo compModel = (CompanyMasterVO) CompanyMasterVO.class.newInstance();
                                CompanyVo compVO = (CompanyVo) dg.findByPrimaryKey(new CompanyVo(),
                                        new CompanyPk(userVO.getCompanyCode()));

                                // for logging the user in Login History
                                InsertDelegate inDg = new InsertDelegate();
                                inDg.insertLoginLog(userVO.getCompanyCode(), user.getUserId());

                                session.setAttribute(ProjectConstants.SESSION_USER, user);
                                session.setAttribute(ProjectConstants.SESSION_COMPANY_CODE, userVO.getCompanyCode());

                                // stores data security
                                storeSecurityInfo(session, user);

                                // stores status approval list
                                retrieveUserApprovalListInfo(mapping, formIn, request, response, user, userVO.getCompanyCode());

                                // get system param
                                SysParamDelegate sysDg = new SysParamDelegate();
                                SysParamVO vo = new SysParamVO();
                                ArrayList sysParam = (ArrayList) sysDg.findByCriteria(vo, null);

                                session.setAttribute(ProjectConstants.SESSION_SYS_PARAM, new SysParamList(sysParam));

//                                ProjectParamsDelegate prjDg = new ProjectParamsDelegate();
//                                ProjectParamSrchCriteria prjCri = new ProjectParamSrchCriteria();
                                ProjectParamSrchCriteria projCrit = new ProjectParamSrchCriteria();

                                String prjCompCode = WebUtil.getAppropriateCompanyCode(session,
                                        ProjectConstants.SP_SHARE_PROJECT_PARAM);
                                projCrit.setSrchCompanyCode(prjCompCode);

                                ArrayList prjParam = (ArrayList) dg.findByCriteria(new ProjectParamVo(), projCrit);

                                session.setAttribute(ProjectConstants.SESSION_PROJECT_PARAM, new ProjectParamsList(prjParam));
                                
                                processActionChangeLang(mapping, formIn, request, response, errors);
                                
                                actionForward = mapping.findForward("success");
                            } else {
                                Logger.warn(this, "otherExecute(), Login FAILED");
                                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.failed"));
                            }
                        } else {
                            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.user.inactive"));
                        }
                    } else {
                        Logger.warn(this, "otherExecute(), Login FAILED, userVO is null");
                        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.failed"));

                    }
                } catch (Exception e) {
                    Logger.error(this, "otherExecute(), error: " + e.getMessage());
                    if (Logger.isTraceLevel()) {
                        e.printStackTrace();
                    }
                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("excpetion.general", e.getMessage()));
                }
            } // if form passses validation

            setHandled(request);
        }

        Logger.debug("otherExecute(), after processActionChangeLang(), System.getProperty(ProjectConstants.SESSION_SYSTEM_LAN): " 
        		+ System.getProperty(ProjectConstants.SESSION_SYSTEM_LANG));
        Logger.debug("otherExecute(), after processActionChangeLang(), Session.getAttribute(ProjectConstants.SESSION_SYSTEM_LAN): " 
        		+ session.getAttribute(ProjectConstants.SESSION_SYSTEM_LANG));

        if (errors.size() > 0) {
            form.setPageMode("prompt_errors");
        }

        saveErrors(request, errors);
        saveToken(request);
        return actionForward;

    }

    protected ActionForward processActionChangeLang(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors actionErrors) {
        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());
        LoginForm form = (LoginForm) formIn;

        try {
            String newLang = CommonUtil.nullToString(form.getSysLang());
            Logger.debug("processActionChangeLang(), got user input lang is: " + newLang);

            if (newLang == null) {
                return actionForward;
            }

            SimplePageEditStyleDelegate dg = new SimplePageEditStyleDelegate();
            SysLangSrchCriteria crit = new SysLangSrchCriteria();
            ArrayList sysLangList = (ArrayList) dg.findByCriteria(new SysLangVo(), crit);
            if ((sysLangList == null) || (sysLangList.size() == 0)) {
                Logger.warn(this, "Please set the system language in the database table");
                return actionForward;
            }
            
            Logger.debug("processActionChangeLang(), PREVIOUS, System.getProperty(ProjectConstants.SESSION_SYSTEM_LAN): " 
            		+ System.getProperty(ProjectConstants.SESSION_SYSTEM_LANG));
            Logger.debug("processActionChangeLang(), PREVIOUS, Session.getAttribute(ProjectConstants.SESSION_SYSTEM_LAN): " 
            		+ session.getAttribute(ProjectConstants.SESSION_SYSTEM_LANG));

            session.removeAttribute(ProjectConstants.SESSION_SYSTEM_LANG);
			session.setAttribute(ProjectConstants.SESSION_SYSTEM_LANG, newLang);
			System.setProperty(ProjectConstants.SESSION_SYSTEM_LANG, newLang);
			Logger.debug("processActionChangeLang(), NEW, set sesion sys lang to: "
					+ session.getAttribute(ProjectConstants.SESSION_SYSTEM_LANG));			

			Logger.debug("processActionChangeLang(), NEW, set system sys lang to: "
					+ System.getProperty(ProjectConstants.SESSION_SYSTEM_LANG));	
			
//			SimplePageEditStyleDelegate spedg = new SimplePageEditStyleDelegate();
//	        ErrorMsgLabelVo errmsgVo = new ErrorMsgLabelVo();
//	        ErrorMsgLabelSrchCriteria errmsgCrit = new ErrorMsgLabelSrchCriteria();
//	        errmsgCrit.setSrchCompanyCode(form.getCompanyCode());
//	        errmsgCrit.setSrchGroupIdFr(DBMENU_GENERAL_MENU);
//	        errmsgCrit.setSrchGroupIdTo(DBMENU_GENERAL_MENU);
//	        errmsgCrit.setSrchMenuIdFr(DBMENU_GENERAL_ERROR);
//	        errmsgCrit.setSrchMenuIdTo(DBMENU_GENERAL_ERROR);
//	        errmsgCrit.setSrchLangCodeFr(newLang);
//	        errmsgCrit.setSrchLangCodeTo(newLang);
//	        errmsgCrit.setSrchObjectTypeFr(DBMENU_OBJECT_TYPE_ERR_MSG);
//	        errmsgCrit.setSrchObjectTypeTo(DBMENU_OBJECT_TYPE_ERR_MSG);
	        
			HashMap errmsgHash = WebUtil.getModuleErrorMessages(form.getCompanyCode(), 
					DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, newLang, DBMENU_OBJECT_TYPE_ERR_MSG);
			
	        ActionErrorUtil sc = new ActionErrorUtil();
	        
	        ErrorMsgLabelPk pk = null;
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_GENERAL_CRITERIA_BLANK,
	    			newLang);	        
	        
	        //sc.ERROR_GENERAL_CRITERIA_BLANK = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_GENERAL_CRITERIA_BLANK, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_GENERAL_DESCRIPTION_BLANK,
	    			newLang);	        
	        //sc.ERROR_GENERAL_DESCRIPTION_BLANK = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_GENERAL_DESCRIPTION_BLANK, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_GENERAL_FIELD_BLANK,
	    			newLang);	        
	        //sc.ERROR_GENERAL_FIELD_BLANK = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_GENERAL_FIELD_BLANK, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_YEAR_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_YEAR_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_YEAR_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_MONTH_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_MONTH_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_MONTH_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_MONTHYEAR_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_MONTHYEAR_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_MONTHYEAR_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_DATE_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_DATE_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_DATE_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_TIME_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_TIME_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_TIME_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_DATE_DATETIME_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_DATE_DATETIME_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_DATE_DATETIME_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_DATE_TIME_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_DATE_TIME_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_DATE_TIME_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NUMBER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_NUMBER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_NUMBER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_POSITIVE_INTEGER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_POSITIVE_INTEGER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_POSITIVE_INTEGER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_POSITIVE_NUMBER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_POSITIVE_NUMBER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_POSITIVE_NUMBER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NEGATIVE_INTEGER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_NEGATIVE_INTEGER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_NEGATIVE_INTEGER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NEGATIVE_NUMBER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_NEGATIVE_NUMBER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_NEGATIVE_NUMBER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NON_NEGATIVE_INTEGER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_NON_NEGATIVE_INTEGER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_NON_NEGATIVE_INTEGER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NON_NEGATIVE_NUMBER_FORMAT,
	    			newLang);	        
	        //sc.ERROR_INVALID_NON_NEGATIVE_NUMBER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_NON_NEGATIVE_NUMBER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
	        pk = new ErrorMsgLabelPk(form.getCompanyCode(),
	        		DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_FROM_GREATER_THAN_TO,
	    			newLang);	        
	        //sc.ERROR_INVALID_FROM_GREATER_THAN_TO = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
	        sc.errorMsgMap.put(sc.ERROR_INVALID_FROM_GREATER_THAN_TO, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());

            pk = new ErrorMsgLabelPk(form.getCompanyCode(),
                    DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_CODE,
                    newLang);
            //sc.ERROR_INVALID_CODE = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
            sc.errorMsgMap.put(sc.ERROR_INVALID_CODE, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
            
            pk = new ErrorMsgLabelPk(form.getCompanyCode(),
                    DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_EMAIL,
                    newLang);
            //sc.ERROR_INVALID_CODE = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
            sc.errorMsgMap.put(sc.ERROR_INVALID_EMAIL, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());
	        
            pk = new ErrorMsgLabelPk(form.getCompanyCode(),
                    DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_LINE_NO,
                    newLang);
            //sc.ERROR_LINE_NO = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
            sc.errorMsgMap.put(sc.ERROR_LINE_NO, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());

            pk = new ErrorMsgLabelPk(form.getCompanyCode(),
                    DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_INTEGER_FORMAT,
                    newLang);           
            //sc.ERROR_INVALID_NON_NEGATIVE_INTEGER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
            sc.errorMsgMap.put(sc.ERROR_INVALID_INTEGER_FORMAT, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());

            pk = new ErrorMsgLabelPk(form.getCompanyCode(),
                    DBMENU_GENERAL_MENU, DBMENU_GENERAL_ERROR, sc.ERROR_INVALID_NDC_DATE,
                    newLang);           
            //sc.ERROR_INVALID_NON_NEGATIVE_INTEGER_FORMAT = ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel();
            sc.errorMsgMap.put(sc.ERROR_INVALID_NDC_DATE, ((ErrorMsgLabelVo)errmsgHash.get(pk)).getObjectWebLabel());

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }

        return actionForward;
    }

    private void storeSecurityInfo(HttpSession session, User user) {
        DynamicQuery dQuery = new DynamicQuery();
        DynamicQueryColumn dqc = new DynamicQueryColumn("COMPANY_CODE", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("USER_NAME", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("USER_GROUP_CODE", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("USER_GROUP_DESC", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("DEPT", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("USER_CODE", null, String.class);
        dQuery.addColumn(dqc);
        dqc = new DynamicQueryColumn("STATUS", null, String.class);
        dQuery.addColumn(dqc);
        dQuery.addTable("V_USER_ACCESS_DEPT");

        StringBuffer sb = new StringBuffer("COMPANY_CODE = '");
        sb.append(user.getCompanyCode());
        sb.append("' AND USER_CODE = '");
        sb.append(user.getUserId());
        sb.append("'");
        dQuery.setWhereStatement(sb.toString());

        Collection resultList = null;
        try {
            resultList = dQuery.execute();
        } catch (Exception e) {

            e.printStackTrace();
        }
        if (resultList != null) {
            session.setAttribute(ProjectConstants.SESSION_USER_DATA_ACCESS_SECURITY, resultList);
        } else {
            Logger.warn(this, "retrieveUserDataSecurityInfo(), there is no user data security info.");
        }
    }

    public void retrieveUserApprovalListInfo(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, User user, String companyCode) {

        HttpSession session = request.getSession(false);

        ActionErrors errors = new ActionErrors();

        LoginForm form = (LoginForm) formIn;
        ActionForward actionForward = new ActionForward(mapping.getInput());

        String action = form.getPageEvent();
        action = (action == null) ? "" : action.trim();

        String userCode = user.getUserId();
        String userGroupCode = user.getUserGroupCode();
        SelectDelegate sdg = new SelectDelegate();
        ArrayList resultList = new ArrayList();

        resultList = sdg.findUserGroupInfo(companyCode, userGroupCode, userCode);

        if (resultList != null) {
            session.setAttribute(ProjectConstants.SESSION_USER_APPROVAL_LIST, resultList);
        } else {
            Logger.warn(this, "retrieveUserApprovalListInfo(), there is no user approval list info.");
        }
    }
}